﻿<cfscript>
/** 
* Course Mark Translater Service
* 
* @hint "Course Mark Translater Service" 
*/ 

component 
	displayname="public.service.handler.LogFactory" 
	output=false 
	accessors=true
	{
		
	/*PROPERTIES*/
	property name="datetimeAdvice" hint="日期时间操作组件";
	property name="sessionAdvice" hint="会话组件";
	property name="securityAdvice" hint="安全组件";
	property name="sequenceLogInfo" hint="日记组件";
	
	/**
	* @hint "初始化对象"
	*/
	public public.service.handler.LogFactory function init() output=false {
		return this;
	}

	
	
	/***************************
	
		日志类型 
		
		1  教师登录日志
		2  学生登录日志
		
		3  导入学生数据
		
		5  学生基本信息修改记录
		6  学生学籍修改记录
		
		7  给学生添加学分指导教师
		9  给学生添加论文指导教师
		
		10 对学生毕业论文管理 
	
	
	*****************************/
	
	
	/**
	* @hint "操作日记"
	* 
	* @type "操作类型"
	* @content "具体描述"
	* @targetId "操作对象"
	*/

	public void function writeLog( required string type, required string content, required string targetId ) output=false {
		
		var sequence = getsequenceLogInfo();
		
		var logId = sequence.getLogId();
		
		/* 当前日期时间字符串 */
		var currentDateTime = getdatetimeAdvice().getCurrentDatetimeString();
			
		//操作人员
		var userId = getsessionAdvice().getAutherUserID();
		
		var ip = getsecurityAdvice().getIP();
		
		var sql = "";
		var queryObj = "";

		transaction{
	
			sql = "INSERT INTO t_loginfo(log_id, type_id, user_id, log_content, log_ip, log_time, target_id) values(
							   :logId, :typeId, :userId, :content, :logIp, :logTime, :targetId  
						)";
						
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="logId", value=logId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="typeId", value=type, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="userId", value=userId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="content", value=content, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="logIp", value=ip, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="logTime", value=currentDateTime, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetId", value=targetId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			break;

		}
		
	}
	
	/*
		日志类型 

		4  班主任给班级添加学生、班主任给班级删除学生
			
	*/
	
	
	/**
	* @hint "操作日记"
	* 
	* @type "操作类型" - (班级添加学生)
	* @content "具体描述"
	* @targetId "操作对象"
	* @classId "班级"
	*/

	public void function clsAddStudent( required string type, required string content, required string targetId, required string classId ) output=false {
		
		var sequence = getsequenceLogInfo();
		
		var logId = sequence.getLogId();
		
		/* 当前日期时间字符串 */
		var currentDateTime = getdatetimeAdvice().getCurrentDatetimeString();
			
		//操作人员
		var userId = getsessionAdvice().getAutherUserID();
		
		var ip = getsecurityAdvice().getIP();
		
		var sql = "";
		var queryObj = "";

		transaction{
	
			sql = "INSERT INTO t_loginfo(log_id, type_id, user_id, log_content, log_ip, log_time, target_id, cls_id) values(
							   :logId, :typeId, :userId, :content, :logIp, :logTime, :targetId, :classId  
						)";
						
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="logId", value=logId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="typeId", value=type, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="userId", value=userId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="content", value=content, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="logIp", value=ip, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="logTime", value=currentDateTime, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetId", value=targetId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="classId", value=classId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			break;

		}
		
	}
	
	/*
		日志类型 

		8  老师给学生添加或者删除课程
		11 考试、提前考试添加或者删除
		12 教学任务添加或者删除
			
	*/
	
	
	/**
	* @hint "操作日记"
	* 
	* @type "操作类型" - (学生选课管理)
	* @content "具体描述"
	* @targetId "操作对象"
	* @classId "教学任务号"
	*/

	public void function stuCourse( required string type, required string content, required string targetId, required string courseId, required string termId ) output=false {
		
		var sequence = getsequenceLogInfo();
		
		var logId = sequence.getLogId();
		
		/* 当前日期时间字符串 */
		var currentDateTime = getdatetimeAdvice().getCurrentDatetimeString();
			
		//操作人员
		var userId = getsessionAdvice().getAutherUserID();
		
		var ip = getsecurityAdvice().getIP();
		
		var sql = "";
		var queryObj = "";

		transaction{
	
			sql = "INSERT INTO t_loginfo(log_id, type_id, user_id, log_content, log_ip, log_time, target_id, cls_id,cid,term_id) values(
							   :logId, :typeId, :userId, :content, :logIp, :logTime, :targetId, :classId, :cid, :term_id   
						)";
						
			queryObj = new Query( datasource=application.dnsMaster );
			
			queryObj.addParam( name="logId", value=logId, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="typeId", value=type, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="userId", value=userId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="content", value=content, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="logIp", value=ip, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="logTime", value=currentDateTime, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="targetId", value=targetId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="classId", value='', cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="cid", value=courseId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="term_id", value=termId, cfsqltype="cf_sql_varchar" );
			
			queryObj.execute( sql=sql );
			
			break;

		}
		
	}
	
	
}
	
</cfscript>